<template>
  <div>
    <!-- 头部 -->
    <header class="site-header jumbotron">
      <div class="container">
        <div class="row">
          <div class="col-xs-12">
            <h1>请发表对Vue的评论</h1>
          </div>
        </div>
      </div>
    </header>
    <!-- 内容区 -->
    <div class="container">
      <!-- 添加评论 -->
      <AddComment :addComment="addComment"/>
      <!-- 评论列表展示 -->
      <CommentList :comments="comments" :delComment="delComment"/>
    </div>
  </div>
</template>

<script>
import AddComment from"./views/AddComment"
import CommentList from"./views/CommentList"

export default{
  name:"App",
  components:{
    AddComment,
    CommentList,
  },
  data(){
    return{
      comments:[
        {
          id:1,
          username:"佳哥",
          content:"打王者"
        },
        {
          id:2,
          username:"雪雪",
          content:"打瑶妹"
        },     
      ]
    }
  },
  methods:{
    addComment(comment){
      this.comments.push({
        id:Date.now(),
        ...comment,
      })
    },
    delComment(index){
      this.comments.splice(index,1);
    }
  }
}

</script>

